package com.woniuxy.microsysserver.service.impl;
import com.woniuxy.microsysserver.dao.BankCardDao;
import com.woniuxy.microsysserver.dao.CouponDao;
import com.woniuxy.microsysserver.entity.BankCardEntity;
import com.woniuxy.microsysserver.entity.CouponEntity;
import com.woniuxy.microsysserver.service.BankcardService;
import com.woniuxy.microsysserver.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Auther: wuson  <br/>
 * Date: 2021/3/11:19:51  <br/>
 * Description:
 */
@Service
public class BankCardServiceImpl implements BankcardService {
    @Autowired(required = false)
    private BankCardDao bankCardDao;

    @Override
    public int addOne(BankCardEntity bankCardEntity) {
        int state = bankCardDao.addOne(bankCardEntity);
        return state;
    }

    @Override
    public List<BankCardEntity> selectAll(String username) {
        List<BankCardEntity> bankCardEntities = bankCardDao.selectAll(username);
        return bankCardEntities;
    }

    @Override
    public BankCardEntity selectByNumber(String number) {
        BankCardEntity bankCardEntity = bankCardDao.selectByNumber(number);
        return bankCardEntity;
    }

    @Override
    public int recharge(BankCardEntity bankCardEntity) {
        BankCardEntity oldBankCardEntity = bankCardDao.selectByid(bankCardEntity.getId());
        BankCardEntity newBankCardEntity = BankCardEntity.builder().id(bankCardEntity.getId()).number(oldBankCardEntity.getNumber()).balance(oldBankCardEntity.getBalance()-bankCardEntity.getRechargeMoney()).build();
        int state = bankCardDao.updateBalance(newBankCardEntity);
        return state;
    }

    @Override
    public BankCardEntity selectByid(int id) {
        BankCardEntity oldBankCardEntity = bankCardDao.selectByid(id);
        return oldBankCardEntity;
    }

    @Override
    public int binding(BankCardEntity bankCardEntity) {
        int state = bankCardDao.binding(bankCardEntity);
        return state;
    }

    @Override
    public BankCardEntity selectBindingByNumber(String number) {
        BankCardEntity bankCardEntity = bankCardDao.selectBindingByNumber(number);
        return bankCardEntity;
    }

//    @Override
//    public int updateOne(BankCardEntity bankCardEntity) {
//        int state = bankCardDao.updateOne(bankCardEntity);
//        return state;
//    }

    @Override
    public int deleteOne(int id) {
        int state = bankCardDao.deleteOne(id);
        return state;
    }


}
